﻿using System;
using HarmonyLib;
using UnityEngine;

namespace PatchWire
{
    public class PrettierConductiveHeavyWattWirePatches
    {
        [HarmonyPatch(typeof(WireRefinedHighWattageConfig))]
        [HarmonyPatch("CreateBuildingDef")]
        [HarmonyPatch(new Type[] { })]
        public static class WireRefinedHighWattageConfig_CreateBuildingDef_Patch
        {
            public static void Postfix(ref BuildingDef __result)
            {
                __result.BaseDecor = TUNING.BUILDINGS.DECOR.BONUS.MONUMENT.COMPLETE.amount;
                __result.BaseDecorRadius = TUNING.BUILDINGS.DECOR.BONUS.MONUMENT.COMPLETE.radius;
            }
        }


        [HarmonyPatch(typeof(WireHighWattageConfig))]
        [HarmonyPatch("CreateBuildingDef")]
        [HarmonyPatch(new Type[] { })]
        public class WireHighWattageConfig_CreateBuildingDef_Patch
        {
            public static void Postfix(ref BuildingDef __result)
            {
                __result.BaseDecor = TUNING.BUILDINGS.DECOR.BONUS.MONUMENT.INCOMPLETE.amount;
                __result.BaseDecorRadius = TUNING.BUILDINGS.DECOR.BONUS.MONUMENT.INCOMPLETE.radius;
            }
        }

        [HarmonyPatch(typeof(Wire), "GetMaxWattageAsFloat")]
        private static class Wire_GetMaxWattageAsFloat_Patch
        {
            // Token: 0x06000012 RID: 18 RVA: 0x00002DD0 File Offset: 0x00000FD0
            private static void Postfix(Wire __instance, ref float __result)
            {
                try
                {
                    __result *= 10;
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                    global::Debug.Log("[PatchWire] " + " - " + ex.Message);
                }
            }
        }
        [HarmonyPatch(typeof(PowerTransformerSmallConfig), "CreateBuildingDef")]
        private static class PowerTransformerSmallConfig_CreateBuildingDef_Patch
        {
            // Token: 0x0600000E RID: 14 RVA: 0x000026FC File Offset: 0x000008FC
            private static void Postfix(PowerTransformerSmallConfig __instance, BuildingDef __result)
            {
                try
                {
                    __result.GeneratorWattageRating *= 10.0f;
                    __result.GeneratorBaseCapacity *= 10.0f;
                    Debug.Log(string.Format("[PatchWire] PowerTransformerSmall - multiplier {0}, new capacity {1}", 10.0f, __result.GeneratorBaseCapacity));
                }
                catch (Exception ex)
                {
                    Debug.Log("[PatchWire] PowerTransformerSmall - " + ex.Message);
                    Debug.LogException(ex);
                }
            }
        }
        [HarmonyPatch(typeof(PowerTransformerConfig), "CreateBuildingDef")]
        private static class PowerTransformerConfig_CreateBuildingDef_Patch
        {
            // Token: 0x0600000D RID: 13 RVA: 0x00002660 File Offset: 0x00000860
            private static void Postfix(PowerTransformerConfig __instance, BuildingDef __result)
            {
                try
                {
                    __result.GeneratorWattageRating *= 10.0f;
                    __result.GeneratorBaseCapacity *= 10.0f;
                    Debug.Log(string.Format("[BiggerCapacity] PowerTransformer - multiplier {0}, new capacity {1}", 10.0f, __result.GeneratorBaseCapacity));
                }
                catch (Exception ex)
                {
                    Debug.Log("[PatchWire] PowerTransformer - " + ex.Message);
                    Debug.LogException(ex);
                }
            }
        }
        //         [HarmonyPatch(typeof(LiquidHeaterConfig))]
        //         [HarmonyPatch("CreateBuildingDef")]
        //         [HarmonyPatch(new Type[] { })]
        //         public class LiquidHeaterConfig_CreateBuildingDef_Patch
        //         {
        //             public static void Postfix(ref BuildingDef __result)
        //             {
        //                 __result.OverheatTemperature = 700.0f;
        //                 __result.SelfHeatKilowattsWhenActive = 256.0f;
        //             }
        //         }

        //         [HarmonyPatch(typeof(LiquidHeaterConfig))]
        //         [HarmonyPatch("ConfigureBuildingTemplate")]
        //         [HarmonyPatch(new Type[]{ typeof(GameObject), typeof(Tag) })]
        //         public class LiquidHeaterConfig_ConfigureBuildingTemplate_Patch
        //         {
        //             public static void Prefix(LiquidHeaterConfig __instance, ref GameObject go,ref Tag prefab_tag)
        //             {
        //                 SpaceHeater spaceHeater = go.GetComponent<SpaceHeater>();
        //                 if(spaceHeater!=null)
        //                 {
        //                     spaceHeater.targetTemperature = 600.0f;
        //                     spaceHeater.minimumCellMass = 1.0f;
        //                 }
        //             }
        //         }
    }
}
